<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./../../WEB-INF/templates/noFooterCompanyTemplate.xhtml">

            <ui:define name="content">
                <form name="compra" id="tpvForm" action='https://sis.sermepa.es/sis/realizarPago' method="POST" target="tpv">
                    <h:panelGrid id="tpvPanelGrid" columns="3">
                        <h:panelGrid rendered="#{tPVBean.chosenCompanyProduct!=null}" columns="3">
                          <input type="hidden" name="Ds_Merchant_MerchantName" value="#{tPVBean.merchantName}"></input>
                          <input type="hidden" name="Ds_Merchant_MerchantCode" value="#{tPVBean.merchantCode}"></input>
                          <input type="hidden" name="Ds_Merchant_Terminal" value="#{tPVBean.merchantTerminal}"></input>
                          <input type="hidden" name="Ds_Merchant_Order" value="#{tPVBean.merchantOrder}"></input>
                          <input type="hidden" name="Ds_Merchant_Amount" value="#{tPVBean.amount}"></input>
                          <input type="hidden" name="Ds_Merchant_Currency" value="#{tPVBean.merchantCurrency}"></input>
                          <input type="hidden" name="Ds_Merchant_TransactionType" value="#{tPVBean.merchantTransactionType}"></input>
                          <input type="hidden" name="Ds_Merchant_MerchantURL" value="#{tPVBean.merchantURL}"></input>
                          <input type="hidden" name="Ds_Merchant_MerchantSignature" value="#{tPVBean.merchantSignature}"></input>
                        </h:panelGrid>
                    </h:panelGrid>
                </form> 
                
                <h:form id="creditCompanyDialogForm">
                    <p:dialog modal="true" style="width:250px;" header="#{messages.AreYouSure}" resizable="false" id="creditCompanyDialog" widgetVar="creditCompanyDialog"  draggable="true" closable="true">  
                        <p:panel id="creditCompanyDialogPanel" styleClass="noBorder noBorder noPadding">
                            <h:panelGrid  styleClass="noBorderSpacing" columns="2"> 
                                 <p:outputLabel for="numberCredits" value="#{messages.Product}" />
                                 <p:outputLabel styleClass="marginLeft20" id="numberCredits" value="#{tPVBean.chosenCompanyProduct.credits} #{messages.Credits}"/>
                                 <p:outputLabel for="price" value="#{messages.TotalToPaid}" />
                                 <p:outputLabel styleClass="marginLeft20" id="price" value="#{tPVBean.chosenCompanyProduct.currentPrice}" />
                            </h:panelGrid>
                            <p:commandButton process="@this" value="#{messages.No}" onsuccess="creditCompanyDialog.hide();" update="creditCompanyDialog"/>  
                            <p:commandButton process="@parent" value="#{messages.Yes}" actionListener="#{tPVBean.confirmBuy()}" oncomplete="creditCompanyDialog.hide();calc();" update="@(#tpvPanelGrid) creditCompanyDialogPanel"/> 
                        </p:panel>
                    </p:dialog>                        
                </h:form>
                <h:form id="creditCompanyForm">
                    <p:growl id="creditCompanyGrowl" showDetail="false" sticky="true" life="4000" />
                    <p:panel styleClass="productBotoneraPanel noPadding noBorder">
                        <p:panel header="#{messages.BuyCompanyProduct}" style="width:340px" styleClass="noPadding noBorder">
                            <ui:repeat value="#{productsCompanyBean.entityList}" var="companyProduct">
                                <p:commandLink update=":creditCompanyDialogForm:creditCompanyDialogPanel" onsuccess="creditCompanyDialog.show();" actionListener="#{productsCompanyBean.chooseEntity(companyProduct)}" styleClass="iconMarginBottom personalIcon smallProductIcon iconMarginRight">
                                    <h:outputText styleClass="iconText" value="#{companyProduct.description}"></h:outputText>
                                </p:commandLink>
                            </ui:repeat>
                        </p:panel>
                        <p:panel styleClass="noMargin noPadding noBorder"></p:panel>
                    </p:panel>
                </h:form>
                
                
                <script type="text/javascript" >
                    function calc(){
                        //vent=window.open("","tpv","width=480,height=475,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no");
                        $("#tpvForm").submit();
                        }
                </script>
            </ui:define>

        </ui:composition>

    </body>
</html>
